<?php

define(C("ACCESSACTION"), true);
import('jinghuan.AdminAction');

/**
 * Class ApiAction
 */
class MarketCheckAction extends AdminAction
{
    function datatable()
    {
        $post = I('post.');
        $post["where"]['status'] = 1;
        $count = D(market_check)->where($post["where"])->count();
        $row = D(market_check)
            ->page($post["page"], $post["length"])
            ->where($post["where"])
            ->order('id desc')
            ->select();

        $this->callback(array(
            'rows' => $row,
            'echo' => $post["echo"],
            'count' => $count
        ));
    }

    function do_add()
    {
        $post = I('post.');

        $result = D(market_check)->add(array(
            "check" => $post['check'],
            "url" => $post['url'],
            "u_time" => time(),
        ));

        $this->callback($result != false);
    }

    function do_edit()
    {
        $post = I('post.');

        D(market_check)->save(array(
            "id" => $post['id'],
            "check" => $post['check'],
            "url" => $post['url'],
            "u_time" => time(),
        ));
        $data = D(market_check)->where(array('id' => $post['id']))->find();

        $this->callback($data);
    }

}